﻿Imports DevExpress.UserSkins
Imports DevExpress.XtraBars
Imports DevExpress.XtraBars.Helpers
Imports DevExpress.XtraBars.Ribbon
Public Class frm_Login
#Region "Khai Báo Biến"
    Dim mvCls_Main As New cls_Main
    Dim mvCls_Logon As New cls_Login
    Dim mvCls_Logfile As New cls_Logfile
    Dim mvCls_UpdateLogfile As New cls_Logfile_Update
    Dim mvCls_SetupUpdate As New cls_Setup_Update
    Private mvcls_CIE_Account_Base As cls_Account = Nothing
    Private mvUrc_FullKeyboard As New urc_FullScreenKeyboard
#End Region
#Region "Hàm Khởi Tạo"
    Private Sub SubM_InitializeForm()
        Try
            SkinHelper.InitSkinPopupMenu(PopupMenu1)
            Me.txtUserName.TabIndex = 1
            Me.txtPassword.TabIndex = 2
            Me.cmdDangNhap.TabIndex = 3
            Me.txtUserName.Text = ""
            Me.txtPassword.Text = ""
            gvTxt_Focus = Me.txtUserName
            With Me.GroupControl3
                .Top = (Me.ClientRectangle.Height / 5) - (.Height / 5)
                .Left = (Me.ClientRectangle.Width / 2) - (.Width / 2)
            End With
            With Me.PanelControl1
                .Top = (Me.ClientRectangle.Height / 2) - (.Height / 2)
                .Left = (Me.ClientRectangle.Width / 2) - (.Width / 2)
            End With
            mod_LoadLanguageForm.SubG_LoginForm()
            mod_Format.Sub_ShowControl(mvUrc_FullKeyboard, 1)
            mvUrc_FullKeyboard.SubM_InitializeForm()
            Me.txtUserName.BackColor = Color.LightSkyBlue
            Me.txtUserName.Focus()
        Catch ex As Exception
            Throw ex
        End Try
    End Sub
#End Region
#Region "FormLoad"
    Private Sub frm_CIE_Logon_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Try
            Me.Visible = False
            spl_FlashForm.ShowDialog()
            Me.Visible = True
            mvCls_Main.SubG_Load()
            Me.SubM_InitializeForm()
            'Thiết lập ngôn ngữ mặc định (1 = Tiếng Việt, 2 = Tiếng Anh)
            Me.rgpLanguage.SelectedIndex = gvByte_Language - 1
            'Lấy thông tin hệ thống
            SubM_LoadSetting()
        Catch ex As Exception

        End Try
    End Sub
#End Region
#Region "Load setting"
    Private Sub SubM_LoadSetting()
        Dim mvObj_DataTable As New DataTable
        Try
            mvObj_DataTable = mvCls_SetupUpdate.FuncG_GetData
            If mvObj_DataTable.Rows.Count = 0 Then
                FunG_Alert("Thông báo lỗi!", "Thông số hệ thống đã bị xóa!" & Chr(13) & "Vui lòng liên hệ với quản lý!", frm_Alert.WTYPE.ERROR)
                End
            Else
                gvBol_RedStatus = mvObj_DataTable.Rows(0)("RED_STATUS")
                gvBol_VatStatus = mvObj_DataTable.Rows(0)("VAT_STATUS")
                gvBol_PrintOrder = mvObj_DataTable.Rows(0)("PRINTORDER")
                gvByte_NumberPrint = mvObj_DataTable.Rows(0)("PRINTNUMBER")
            End If
        Catch ex As Exception

        End Try
    End Sub
#End Region
#Region "Lấy Thông tin Người Dùng"
    Private Function FuncM_GetPermit() As cls_Account
        Try
            Dim mvStr_HashPassMD5 As String = getMd5Hash(Me.txtPassword.Text.Trim)
            Dim wcls_ERP_Account_Update As New cls_Account_Update
            mvcls_CIE_Account_Base = wcls_ERP_Account_Update.FuncG_GetLoginInfo(Me.txtUserName.Text.Trim, mvStr_HashPassMD5)
        Catch ex As Exception
            Throw ex
        End Try
        Return mvcls_CIE_Account_Base
    End Function
#End Region
#Region "Hàm kiểm tra"
    Private Sub SubM_Logon()
        Try
            If FuncM_GetPermit() Is Nothing Then
                FunG_Alert("Thông báo", "Tài khoản này không tồn tại!", frm_Alert.WTYPE.ERROR)
                Form.ActiveForm.ActiveControl = Me.txtUserName
                Me.txtUserName.BackColor = Color.LightSkyBlue
                Me.txtPassword.BackColor = Color.White
                gvTxt_Focus = Me.txtUserName
            Else
                If FuncM_GetPermit.Status Then
                    gvStr_Permit = FuncM_GetPermit.Permit
                    frm_MainMenu.Show()
                    SubM_PhanQuyen()
                    Me.Hide()
                Else
                    FunG_Alert("Thông báo", "Tài khoản này đang bị khóa!" & Chr(13) & " Vui lòng liên hệ với người quản trị!", frm_Alert.WTYPE.ERROR)
                    Form.ActiveForm.ActiveControl = Me.txtUserName
                    Me.txtUserName.BackColor = Color.LightSkyBlue
                    Me.txtPassword.BackColor = Color.White
                    gvTxt_Focus = Me.txtUserName
                End If
            End If
            Me.txtUserName.Text = ""
            Me.txtPassword.Text = ""
        Catch ex As Exception
            Throw ex
        End Try
    End Sub
#End Region
#Region "Phân Quyền"
    Public Shared Sub SubM_PhanQuyen()
        Try
            frm_MainMenu.cmdSales.Enabled = String.Equals(gvStr_Permit(0), "1"c)
            frm_MainMenu.cmdFastFood.Enabled = String.Equals(gvStr_Permit(0), "1"c)
            frm_MainMenu.cmdSetup.Enabled = String.Equals(gvStr_Permit(1), "1"c)
            frm_MainMenu.cmdReport.Enabled = String.Equals(gvStr_Permit(2), "1"c)
            frm_MainMenu.cmdStore.Enabled = String.Equals(gvStr_Permit(3), "1"c)
            'Chức năng hủy bàn
            frm_Table.cmdDelete.Enabled = String.Equals(gvStr_Permit(5), "1"c)
        Catch ex As Exception

        End Try
    End Sub
#End Region
#Region "Change textbox focus"
    Private Sub ActiveFocus(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtUserName.Enter, txtPassword.Enter
        Try
            Dim mvCtr_ActiveControl As New Control
            mvCtr_ActiveControl = Form.ActiveForm.ActiveControl.Parent
            If mvCtr_ActiveControl.Name = "txtPassword" Then
                Me.txtUserName.BackColor = Color.White
                Me.txtPassword.BackColor = Color.LightSkyBlue
                gvTxt_Focus = Me.txtPassword
            ElseIf mvCtr_ActiveControl.Name = "txtUserName" Then
                Me.txtUserName.BackColor = Color.LightSkyBlue
                Me.txtPassword.BackColor = Color.White
                gvTxt_Focus = Me.txtUserName
            End If
        Catch ex As Exception

        End Try
    End Sub
#End Region
#Region "Kết nối tạm thời"
    Private Sub cmdDangNhap_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdDangNhap.Click
        Try
            If Me.txtUserName.Text.ToUpper = "LEVUEPOS" And Me.txtPassword.Text = "" Then
                End
            Else
                gvProp_AccUser = Me.txtUserName.Text.Trim
                SubM_Logon()
            End If
        Catch ex As Exception
            Throw ex
        End Try
    End Sub
#End Region
#Region "Thay đổi ngôn ngữ"
    Private Sub rgpLanguage_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rgpLanguage.SelectedIndexChanged
        Try
            If Me.rgpLanguage.SelectedIndex = 0 Then
                gvByte_Language = 1
            Else
                gvByte_Language = 2
            End If
            mod_LoadLanguageForm.SubG_LoginForm()
            mvUrc_FullKeyboard.SubM_InitializeForm()
        Catch ex As Exception

        End Try
    End Sub
#End Region
#Region "Thay đổi skin"
    Private Sub SimpleButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SimpleButton1.Click
        Me.PopupMenu1.ShowPopup(System.Windows.Forms.Cursor.Position)
    End Sub
#End Region
#Region "Nút tắt máy"
    Private Sub cmdTatMay_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdTatMay.Click
        frm_Shutdown.ShowDialog()
    End Sub
#End Region
End Class